<template>
	<view v-if="useUserInfo.userInfo.id==''">
		<loginVue></loginVue>
	</view>
	<view class="my">
		<view class="bg"></view>
		<view class="personal">
			<view class="name-profile">
				<image class="head" :src="useUserInfo.userInfo.avatarUrl" mode="widthFix"/>
				<view class="name">{{useUserInfo.userInfo.nickName}}</view>
			</view>
			<view class="menu-list">
				<view class="menu-item" @click="navigateTo('../../pages/personalData/personalData')">
					<text>个人资料</text>
					<text class="arrow">></text>
				</view>
				<view class="menu-item" @click="navigateTo('../../pages/userAddress/userAddress')">
					<text>地址管理</text>
					<text class="arrow">></text>
				</view>
				<view class="menu-item" @click="navigateTo('../../pages/orders/orders')">
					<text>我的订单</text>
					<text class="arrow">></text>
				</view>
				<view class="menu-item" @click="navigateTo('../../pages/userComment/userComment')">
					<text>我的评价</text>
					<text class="arrow">></text>
				</view>
				<view class="menu-item" @click="logout">
					<text>退出登录</text>
					<text class="arrow">></text>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
	import loginVue from '@/component/login/login.vue';
	import { onLoad } from "@dcloudio/uni-app"
	import { useUserStore, useCart, useUserAddressStore } from '@/store/index';
	import { post } from '/hooks/req.js';
	import { ref } from 'vue';
	
	let useUserInfo = useUserStore()
	let userCart = useCart()
	let userAddressStore = useUserAddressStore()
	let nickName = ref(useUserInfo.userInfo.nickName)
	
	// 页面跳转函数
	const navigateTo = (url) => {
		uni.navigateTo({ url })
	}
	
	//判断用户是否登录
	onLoad(() => {
		if (uni.getStorageSync("user")) {
			useUserInfo.userInfo = uni.getStorageSync("user")
		}
	})
	
	//退出登录
	const logout = () => {
		useUserInfo.$reset()
		userCart.$reset()
		userAddressStore.$reset()
		uni.removeStorage({
			key: "user"
		})
		uni.removeStorage({
			key: "token"
		})
	}
</script>

<style scoped lang="scss">
	.bg {
		width: 100%;
		height: 500rpx;
		background-color: #ff6700;
	}
	
	.personal {
		min-height: 650rpx;
		background: linear-gradient(to bottom, rgba(255, 255, 255, 0.8), rgba(255, 255, 255, 0.7));
		margin: 20rpx;
		border-radius: 20rpx 20rpx 0 0;
		margin-top: -250rpx;
		position: relative;
		box-shadow: 0 10rpx 20rpx rgba(0, 0, 0, 0.3);
		z-index: 10;
		padding-bottom: 30rpx;
		
		.name-profile {
			padding: 35rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			
			.head {
				margin-right: 5px;
				border-radius: 50%;
				width: 150rpx;
				height: 150rpx;
			}
			
			.name {
				font-size: 35rpx;
				margin-left: 5px;
				font-weight: 600;
			}
		}
		
		.menu-list {
			margin-top: 50rpx;
			padding: 0 20rpx;
			
			.menu-item {
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 30rpx 20rpx;
				margin-bottom: 2rpx;
				background-color: rgba(255, 255, 255, 0.9);
				font-size: 32rpx;
				color: #333;
				border-bottom: 1px solid #eee;
				
				&:last-child {
					border-bottom: none;
				}
				
				.arrow {
					color: #999;
					font-size: 28rpx;
				}
				
				&:active {
					background-color: rgba(255, 255, 255, 0.7);
				}
			}
		}
	}
</style>